<html>
<head>

<script>

var navigate = true;

// TODO(gcasto): Not sure why this is necessary, but calling
// window.domAutomationController directly in setTimeout seemt to causes the
// function to be evaluated inline.
function delayedUpload() {
  window.domAutomationController.send("FETCH_FINISHED");
}

function send_fetch() {
  fetch("done.html")
    .then(res => res.text())
    .then(
      function() {
        if (navigate) {
          window.top.location.href = "done.html";
        } else {
          // Pretend like auth succeeded by hiding the login and signup forms.
          document.getElementById("testform").style.display = "none";
          document.getElementById("signup_testform").style.display = "none";
          // Delay upload so that handler in PasswordAutofillAgent can be run
          // first. This will happen immediately after JS execution ends, so
          // this shouldn't introduce any timing dependent flakes.
          setTimeout(delayedUpload, 0);
        }
      }
    )
}

</script>
</head>
<body>
<form onsubmit="send_fetch(); return false;" id="testform">
  <input type="text" id="username_field" name="username_field">
  <input type="password" id="password_field" name="password_field">
  <input type="submit" id="submit_button" name="submit_button">
</form>

<form action="password_fetch_submit.html" onsubmit="send_fetch(); return false;"
      id="signup_testform">
  <input type="text" id="signup_username_field" name="signup_username_field">
  <input type="password" id="signup_password_field"
         name="signup_password_field" autocomplete="new-password">
  <input type="password" id="confirmation_password_field"
         name="confirmation_password_field" autocomplete="new-password">
  <input type="submit" id="signup_submit_button" name="signup_submit_button">
</form>
</body>
</html>
